Repository navigation
perf(remote): let lease admission check a reused lease instead of a heartbeat - #5151
Conversation
Size Report
Startup median (7 runs, lower is better):
|
There was a problem hiding this comment.
All reported issues were addressed across 18 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
This comment has been minimized.
This comment has been minimized.
…eartbeat Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on a2120d3. The verdict and the full list are in the summary comment.
An admission-checked request reads lease-admission from /health, so it goes health-first on /rpc even on a checked connection. Lease-free commands there still send one checked request. Fill redaction restores details.dispatched and details.reason only when they are daemon vocabulary. The CLI loads the lease-admission dispatch on demand. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Keeps cli.ts and daemon-client-transport.ts under the line limit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
a2120d3 to
3708303
Compare
|
Pushed 3708303, rebased on current main (the earlier four commits are squashed into 4953438).
Local tests, lint, format, typecheck and layering pass; CI is pending. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 3708303. The verdict and the full list are in the summary comment.
Refusing before teardown now applies only to a request that would do device work under the expired lease. A close or an admission-exempt command ends the session at once, and a close also ends one whose lease the registry no longer holds. Its refusal states no dispatch disclosure, since teardown may have run. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
… input - A request naming its session's expired lease in another spelling is refused before teardown, not after it. - A lease command also ends a session whose lease the registry removed, while no other request holds that session. - A rerun after a lease refusal reuses the fill --text-stdin value. batch, replay and test keep the heartbeat, since they read scripts while building the request. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on eed7a80. The verdict and the full list are in the summary comment.
A close or lease command that found a busy session skipped the teardown and nothing queued it. It now starts the daemon's lease end, which runs once no other request holds the session. A close waits for it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
At 39a7e8a, the code needs changes before merge. The main problem is that some remote work can now run under a stored lease that no heartbeat checked. This can break the Expo and React Native flow where Could an expired lease reach Metro setup here? Take a Metro proxy profile ( connection-lease-admission.ts:89 returns A second independent pass found a related path at connection-runtime.ts:123. connection-lease-transaction.ts:248 uses the stored lease instead of a heartbeat, so deferred Metro setup runs with an unchecked lease. If preparation succeeds and admission then rejects that lease, the first attempt has already saved the runtime. The retry may reuse those bridge hints with the new lease, because connection-metro-runtime.ts:85 checks the platform. Could the same fix as in the first point cover this? Keep the heartbeat whenever the existing preparation predicate will run, including with explicit Metro overrides, and decide this before the lease is acquired or reused. A second independent pass found that a stale record may now hide a replaced lease. A record still names lease A, and another client with the same scope has replaced it with B and opened the same session. The base heartbeats A, gets A second independent pass found that the bypass may run without a daemon instance fence. If a proxy or health adapter reports A second independent pass found that command overrides may change which lease is admitted. A record from daemon A names lease L, daemon B has its own L under another run, and the command passes A second independent pass found that a daemon answer may cause a second dispatch. connection-lease-admission.ts:152 treats the reason A second independent pass found a possible deadlock. Two sessions on different devices share one lease, each has a queued A second independent pass found that a A second independent pass found that Not blocking: these can be taken or left: give one owner the list of commands that upload before their RPC, since connection-lease-admission.ts:43 repeats daemon-artifacts.ts:48 and The earlier review threads are fixed at this commit and can be resolved: the separate capability probe is gone; the local dispatch helper is deleted; the claim about stored capabilities has no symbol left; the no-resend table now asserts the details; only typed disclosure and lease reason values skip redaction; All checks pass at this commit. An earlier cancelled "Body rules" run checks only the PR description, and its re-run passed. Not verified here: no tests were run, and the claims that the new tests fail on the base or the previous head were checked by reading only. It was not checked whether the external Metro bridge accepts or rejects an expired lease, though either result differs from the base. The live timing in the PR description predates the rebase and four later commits. It was accepted only for the hot path, which those commits did not change; the changed refusal, teardown and rerun route is covered by Before merge, the heartbeat must stay when the command prepares a lease-scoped Metro runtime, and a noncanonical lease ID must be made canonical or keep the heartbeat. The other points above also need a fix or an answer. Validation should show that |
…t does CLI: the heartbeat stays for Metro preparation, fill --text-stdin, a stored lease id that is not canonical, and a command whose daemon or owner scope is not the saved connection's. Only the client's own pre-send guard falls back for a daemon without lease-admission, and that capability needs every instance ID. Daemon: an ended lease named against another session lease is the inactive refusal. Device work under a lease that is not live is refused before teardown, a refusal after a teardown claims no dispatch verdict, and no request waits for a whole-lease end under its execution locks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Re the review, addressed in 6082299:
Non-blocking: uploads now use |
The capability refusal table has no outside reader since the CLI matches the refusal class. Binding the lease end outside a request's locks moves to the execution-lock module. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
At b58d303, one problem still needs a code change: a proxy can enable lease admission without identifying its upstream daemon. The other nine points from the earlier review are fixed. A second independent pass found that the missing-upstream-ID point is still open in one case. On the first health check, or on the refresh after an instance mismatch, a proxy or health adapter can report service These earlier threads no longer apply and can be resolved: the separate capability probe is gone, and capability comes from the command's own The cancelled "Body rules" check is likely unrelated to the code, since it validates only the PR description. The other 22 checks pass. Not verified here: no tests were run. It was judged only by reading that the new Metro ordering, two-closes deadlock and admission-order tests would fail on 39a7e8a. The Before merge, the proxy case needs the fix and its test, and "Body rules" needs a re-run. |
…upstream A health answer from agent-device-proxy with no upstream named only the proxy's instance, so nothing held the next request to the daemon that checks the lease. Such an answer now takes the heartbeat. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Re the follow-up, fixed in 53800bd: A CLI test against a proxy answer with no upstream covers both: the first check sends heartbeat then |
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
|
At 53800bd, the remaining problem from the earlier review is fixed, and no code change is still needed. remoteDaemonCapabilities now counts a proxy's The cancelled "Body rules" check is likely unrelated to the code, since it validates only the PR description. The other 22 checks pass, including the jobs that run the changed daemon-client and CLI tests. Not verified here: no tests were run locally, and it was judged only by tracing the b58d303 helper that the two new CLI cases and the new unit case would catch the old behavior. A non-proxy health adapter that omits Before merge, "Body rules" needs a re-run. |
Summary
Admission already renews a lease, so the CLI skips the heartbeat on a reused one when that request's
/healthreportslease-admissionwith every instance ID (a proxy's only through its upstream). An undispatched inactive-lease refusal, or the client's own unsent refusal, reruns once. Device commands go from 3 requests to 2.The heartbeat stays for
macos-appand runtime-backed leases, admission-exempt commands, installs,batch/replay/test,fill --text-stdin,--save-script, Metro preparation, non-canonical lease IDs, another daemon or owner scope than the saved connection, and by-spec opens naming a spec, selector, or no stored device. Marked requests never take/rpc/checked; one request per step there is a follow-up.Daemon: device work on a dead lease is refused before teardown.
closeand lease commands still end the session; for a removed lease they start its lease end without waiting. The CLI daemon transport moved modules (line limit).Security
No resend on timeouts, 5xx, scope mismatch, a daemon-claimed unsupported capability, or missing
nodisclosure. Refusals after teardown claim no verdict. Fill redaction restores only typeddispatchedand leasereason.Validation
Head 53800bd on b69cf45: 233 lease, changed, wire-compat and eager-closure test files (3069 tests), lint, typecheck, layering and Fallow pass (6082299 ran 828 files). Review fixes have tests failing without them; Metro
openafter lease expiry heartbeats, allocates, sets up the bridge, then opens on one lease. Not run on a device; CI pending.Hot-path timing from an earlier head (50 ms each way, emulator, n=10):
🤖 Generated with Claude Code